<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition>
	<h:panelGrid columns="1" style="width:100%;height:100%">
		<h:outputText value="System error: Order model List is null"
			rendered="#{orderModel.list == null}" />
		<h:outputText value="System error: Order model current is null"
			rendered="#{orderModel.current == null}" />

		<h:panelGrid columns="8" style="font-size:0.8em;" width="100%">
			<h:panelGrid columns="2">
				<p:commandButton ajax="true" value="Reload"
					update=":listForm,:detailForm" style="float:left"
					actionListener="#{orderController.loadByQuery}" />
				<p:commandButton actionListener="#{orderModel.orderQuery.clear}"
					ajax="true" update=":listForm,:headerForm" value="Clear conditions"></p:commandButton>
			</h:panelGrid>
			<h:panelGroup>
				<h:outputText value="Status:"></h:outputText>
				<p:selectOneMenu value="#{orderModel.orderQuery.status}">
					<f:selectItems value="#{orderModel.availableStatus}"></f:selectItems>
				</p:selectOneMenu>
			</h:panelGroup>
			<h:panelGroup>
				<h:outputText value="Location:"></h:outputText>
				<p:selectOneMenu id="locationSelectMenu"
					value="#{orderModel.orderQuery.location}"
					converter="#{locationConverter}"
					validator="#{validator.validateDropOffLocation}">
					<f:selectItem itemLabel=""></f:selectItem>
					<f:selectItems value="#{locationModel.list}" var="location"
						itemLabel="#{location.number}:#{location.address} (#{location.postCode})"
						itemValue="#{location}" />
				</p:selectOneMenu>

				<p:commandButton
					actionListener="#{locationController.initOrderByNumber}"
					ajax="true" update=":dialogForm,:headerForm" value="Choose"
					oncomplete="locationDlg.show()"></p:commandButton>
			</h:panelGroup>

			<h:panelGroup>
				<h:outputText value="Required Date:"></h:outputText>
				<p:calendar value="#{orderModel.orderQuery.requiredDate}" />
			</h:panelGroup>

			<h:commandLink value="Print List"
				style="color:green;font-weight:bold">
				<p:fileDownload value="#{orderController.orderListPdf}"></p:fileDownload>
			</h:commandLink>
			<h:commandLink value="Print Detail List">
				<p:fileDownload value="#{orderController.orderDetailListPdf}"></p:fileDownload>
			</h:commandLink>
			
			<p:commandButton value="Send email to customers" ajax="true" oncomplete="sendEmailDlg.show()"  update=":dialogForm"  style="foat:right" ></p:commandButton>

		</h:panelGrid>
		<p:dataTable id="orderListTable" value="#{orderModel.list}"
			var="order" filteredValue="#{orderModel.filteredList}"
			filterEvent="enter" rowKey="#{order.id}"
			selection="#{orderModel.current}" selectionMode="single"
			rendered="#{orderModel.isShowListPanel}" paginator="true" rows="10"
			rowsPerPageTemplate="5,7,10,15,20,30,40,50" style="font-size:0.95em"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
			<p:ajax event="rowSelect" update=":detailForm,:headerForm"
				listener="#{orderController.onRowSelect}"></p:ajax>

			<p:column headerText="Number" sortBy="#{order.number}"
				style="max-width:90px">
				<h:outputText value="#{order.number}" />
			</p:column>
			<p:column filterBy="#{order.customer.lastName}"
				filterStyle="max-width:60px" filterMatchMode="contains"
				style="max-width:80px">
				<h:outputText value="#{order.customer.lastName}"
					title="#{order.customer.telephone} #{order.customer.email}" />
			</p:column>
			<p:column filterBy="#{order.customer.firstName}"
				filterStyle="max-width:60px" filterMatchMode="contains"
				style="max-width:80px">
				<h:outputText value="#{order.customer.firstName}"
					title="#{order.customer.telephone} #{order.customer.email}" />
			</p:column>
			<p:column headerText="Telephone" sortBy="#{order.customer.telephone}">
				<h:outputText value="#{order.customer.telephone}" />
			</p:column>
			<p:column headerText="Email" sortBy="#{order.customer.email}">
				<h:outputText value="#{order.customer.email}" />
			</p:column>
			<p:column sortBy="#{order.customer.dropOffLocation.address}"
				filterBy="#{order.customer.dropOffLocation.address}"
				filterMatchMode="contains">
				<h:outputText
					value="#{order.customer.dropOffLocation.number} : #{order.customer.dropOffLocation.address}" />
			</p:column>

			<p:column headerText="Status" sortBy="#{order.status.label}">
				<h:outputText value="#{order.status.label}" />
			</p:column>
			<p:column headerText="Ordered Date" sortBy="#{order.orderedDate}">
				<h:outputText value="#{order.orderedDate}" />
			</p:column>
			<p:column headerText="Req. date" sortBy="#{order.requiredDate}">
				<h:outputText value="#{order.requiredDate}" />
			</p:column>

			<p:column headerText="Auto Action">
				<p:commandButton value="Confirm" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{orderController.autoConfirmCurrent}"
					rendered="#{order.canConfirm}" />
				<p:commandButton value="Prepare" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{orderController.autoPrepareCurrent}"
					rendered="#{order.canPrepare}" />
				<p:commandButton value="Deliver" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{orderController.deliverCurrent}"
					rendered="#{order.canDeliver}" />
				<p:commandButton value="Pickup" ajax="true"
					update=":listForm,:detailForm,:headerForm"
					actionListener="#{orderController.pickupCurrent}"
					rendered="#{order.canPickup}" />
				<p:commandButton value="Pay" ajax="true" oncomplete="payDlg.show()"
					actionListener="#{orderController.prePayCurrent}"
					update=":dialogForm" rendered="#{order.canPay}" />
			</p:column>
			<ui:remove>
				<p:column headerText="Total charged"
					sortBy="#{order.deliveredTotalChargeLabel}"
					filterBy="#{order.deliveredTotalChargeLabel}"
					filterMatchMode="contains">
					<h:outputText value="#{order.deliveredTotalChargeLabel}" />
				</p:column>

				<p:column headerText="Paid amount" sortBy="#{order.paidAmount}"
					filterBy="#{order.paidAmount}" filterMatchMode="contains">
					<h:outputText value="#{order.paidAmount}" />
				</p:column>
			</ui:remove>
		</p:dataTable>
	</h:panelGrid>
</ui:composition>
</html>